<?php
namespace ORG;
//D:\Component\curl\curl.exe -d "LoginName=zphjr&LoginPassword=666666" http://121.42.201.176:9090/V2.0/WebServiceAPI.asmx/Login
//D:\Component\curl\curl.exe -d '{"LoginName":"zphjr","LoginPassword":"666666"}' http://121.42.201.176:9090/V2.0/WebServiceAPI.asmx/Login
class GPS{
	public function __construct(){
		//Import('@.ORG.Des');
		$this->UserInfo= null; 
		$this->ApiMap=array(
			'Login'=>array(
				'LoginName'=>'zphjr',
				'LoginPassword'=>\ORG\Des::encrypt(base64_encode('666666')),
			),
			'UpdatePassword'=>array(
				'UserCode'=>'',
				'OldPassWord'=>'',
				'NewPassWord'=>''
			),
			'GetUserInfo'=>array(
				'UserCode'=>''
			),
			'GetHomeIndex'=>array(
				'UserCode'=>''
			),
			'GetLongTimeOffLine'=>array(
				'UserCode'=>''
			),
			'GetLongTimeNextPage'=>array(
				'UserCode'=>'',
				'PageIndex'=>'1'
			),
			'GetAboutExpire'=>array(
				'UserCode'=>''
			),
			'GetGroupList'=>array(
				'UserCode'=>''
			),
			'GetDeviceInfoList'=>array(
				'UserCode'=>''
			),
			'UpdateDeviceInfoCache'=>array(
				'UserCode'=>'',
				'CacheTime'=>''
			),
			'GetDeviceInfo'=>array(
				'DeviceNumber'=>''
			),
			'UpdateDeviceInfo'=>array(
				'DeviceNumber'  =>'',
				'DeviceName'    =>'',
				'Plate'         =>'',
				'GroupCode'     =>'',
				'ValidityDate'      =>'',
				'DeviceModel'       =>'',
				'SIM'           =>'',
				'Contact'       =>'',
				'TelePhone'     =>'',
			),
			'GetLKLocation'=>array(
				'DeviceNumber'=>''
			),
			'SetGeofence'=>array(
				'FenceId'=>'',
				'UserCode'=>'',
				'DeviceNumber'=>'',
				'FenceName'=>'',
				'Lat'=>'',
				'Lng'=>'',
				'Radius'=>'',
				'MapType'=>'',
				'OutAlarm'=>'',
				'IntoAlarm'=>'',
			),
			'GetGeoFence'=>array(
				'DeviceNumber'  =>'',
				'UserCode'      =>'',
			),
			'DeleteFence'=>array(
				'FenceId'=>''
			),
			'GetAlarmSet'=>array(
				'UserCode'=>''
			),
			'UpdateAlarmSet'=>array(
				'UserCode'      =>'',
				'OutAlarm'      =>'',
				'IntoAlarm'     =>'',
				'SOSAlarm'      =>'',
				'OverSpeedAlarm'=>'',
				'PowerAlarm'    =>'',
				'VibrationAlarm'=>'',
				'DisplaceAlarm' =>'',
			),
			'GetHistoryLocation'=>array(
				'DeviceNumber'  =>'',
				'StartTime'     =>'',
				'EndTime'       =>'',
				'TimeZone'      =>'',
				'MinID'         =>'',
			),
			'GetHistoryAlarmList'=>array(
				'UserCode'      => '',
				'DeviceNumber'  => '',
				'SearchType'    => '',
				'PageIndex'     => '',
			),
			'GetAnalysisDataList'=>array(
				'DeviceNumber'=>'',
				'TimeZone'=>'8.0',
				'PageIndex'=>'0'
			),
			'GetLKLocation'=>array(
				'UserCode'=>''
			),
			'SendCommandForFrequency'=>array(
				'DeviceNumber'  =>'',
				'Number'        =>'',
			),
			'SendCommandForWorkModel'=>array(
				'DeviceNumber'  =>'',
				'IsContinuous'  =>'',
				'IsCarChase'    =>'',
				'CarChaseValue' =>'',
				'IsCommon'      =>'',
				'CommonValue'   =>'',
				'IsLocation'    =>'',
				'LocationWay'   =>'',
			),
			'SendCommandFoDateSet'=>array(
				'DeviceNumber'=>'',
				'IsUpdate'=>'',
				'TimePoint'=>'',
			),
			'SendCommandForReset'=>array(
				'DeviceNumber'=>''
			),
			'GetSoftwareVersion'=>array(
				'SoftwareVersion'=>''
			),
			'GetUserChildList'=>array(
				'UserName'=>'',
				'UserCode'=>'',
				'IsParent'=>'',
			),
			'GetSearchUserChild'=>array(
				'UserName'=>'',
				'UserCode'=>'',
				'IsParent'=>'',
			)
		);
	}
	function post($url, $data = null){
		$url ='http://121.42.201.176:9090/V2.0/WebServiceAPI.asmx/'.$url;
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		if (!empty($data)){
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, 'request='.json_encode($data));
		}
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($ch);
		curl_close($ch);
		P($output);
		$ret = json_decode($output,true);
		//P($data);
		//P($ret);
		if($ret['Code'] == 0){
			return $ret;
		}else{
			$this->error($ret['Code'],$ret['ErrMsg']);
			exit;
		}
	}
	function __call($name,$args){
		if(!$this->UserInfo && $name!='Login'){
			$ret = $this->Login();
			$this->UserInfo = $ret['UserInfo'];
		}
		$args = $args[0];
		$data=$this->ApiMap[$name];
		foreach ($data as $k => $v) {
			$data[$k] = isset($args[$k]) ? $args[$k] : $v;
		}
		if(isset($data['UserCode']) && empty($data['UserCode'])){
			$data['UserCode'] = $this->UserInfo['UserCode'];
		}
		//P($data);
		return $this->post($name,$data);
	}
	function error($code,$msg){
		exit($msg);
	}
}
?>